<template>
  <div class="create-order">
    <div class="address-wrap">
      <div class="name">
        <span>{{addressInfo.userNam}}</span>
        <span>{{addressInfo.userPhon}}</span>
      </div>
      <div class="address">
        {{addressInfo.provinceName}} {{addressInfo.cityName}} {{addressInfo.regionName}} {{addressInfo.detailAddress}}
      </div>
      <van-icon class="arrow" name="arrow" />
    </div>
    <div class="good">
      <div class="good-item" v-for="(item, index) in cartlist" :key="index">
        <div class="good-img"><img :src="$filters.imgPrefix(item.goodsCoverImg)"></div>
        <div class="good-desc">
          <div class="good-title">
            <span>{{item.goodsName}}</span>
            <span>x{{item.goodsCount}}</span>
          </div>
          <div class="good-btn">
            <div class="price">¥{{item.sellingPrice}}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="pay-wrap">
      <div class="price">
        <span>商品金额</span>
        <span>¥{{total}}</span>
      </div>
      <van-button class="pay-btn" :color="primaryColor" type="primary" block @click="onCreateOrder">生成订单</van-button>
    </div>
    <PayPopup v-model="visible" :orderNo="orderNo" />
  </div>
</template>

<script setup>
import {defineAsyncComponent} from 'vue'
import {useRoute, useRouter} from 'vue-router'
import useThemeStore from '@/store/theme'
import useOrder from '@/hooks/useOrder'

const PayPopup = defineAsyncComponent(() => import('@/components/PayPopup'))

const route = useRoute()
const router = useRouter()
const {primaryColor} = useThemeStore()
const {
  cartlist, addressInfo, visible, orderNo, total,
  onCreateOrder
} = useOrder(useRoute())

function onClose() {
  router.push({path: '/order'})
}
</script>

<style lang="less" scoped>
@import '@/assets/style/var.less';
@import '@/assets/style/mixin.less';

.create-order {
  background: @background-p;
  .address-wrap {
    margin-bottom: 20px;
    background: @background;
    position: relative;
    font-size: @font-size-p;
    padding: 15px;
    color: #222333;
    .name, .address {
      margin: 10px 0;
    }
    .arrow {
      position: absolute;
      right: 10px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 20px;
    }
    &::before {
      position: absolute;
      right: 0;
      bottom: 0;
      left: 0;
      height: 2px;
      background: -webkit-repeating-linear-gradient(135deg, #ff6c6c 0, #ff6c6c 20%, transparent 0, transparent 25%, #1989fa 0, #1989fa 45%, transparent 0, transparent 50%);
      background: repeating-linear-gradient(-45deg, #ff6c6c 0, #ff6c6c 20%, transparent 0, transparent 25%, #1989fa 0, #1989fa 45%, transparent 0, transparent 50%);
      background-size: 80px;
      content: '';
    }
  }
  .good {
    margin-bottom: 120px;
  }
  .good-item {
    padding: 10px;
    background: @background;
    display: flex;
    .good-img {
      img {
        .wh(100px, 100px)
      }
    }
    .good-desc {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      flex: 1;
      padding: 20px;
      .good-title {
        display: flex;
        justify-content: space-between;
      }
      .good-btn {
        display: flex;
        justify-content: space-between;
        .price {
          font-size: 16px;
          color: red;
          line-height: 28px;
        }
        .van-icon-delete {
          font-size: 20px;
          margin-top: 4px;
        }
      }
    }
  }
  .pay-wrap {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: @background;
    padding: 10px 0;
    padding-bottom: 50px;
    border-top: 1px solid #e9e9e9;
    >div {
      display: flex;
      justify-content: space-between;
      padding: 0 5%;
      margin: 10px 0;
      font-size: @font-size-p;
      span:nth-child(2) {
        color: red;
        font-size: 18px;
      }
    }
    .pay-btn {
      position: fixed;
      bottom: 7px;
      right: 0;
      left: 0;
      width: 90%;
      margin: 0 auto;
    }
  }
}
</style>